package com.qianfeng.missfood.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.qianfeng.missfood.R;
import com.qianfeng.missfood.bean.ChannelItemEntity;

import java.util.List;

/**
 * Created by Carmen on 2015/8/18.
 */
public class FoodChannelAdapter extends AppBaseAdapter<ChannelItemEntity> {

    public FoodChannelAdapter(List<ChannelItemEntity> list, Context context) {
        super(list, context);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_channel_gv, parent, false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        bitmapUtils.display(vh.imageView, list.get(position).getIcon());
        vh.textView.setText(list.get(position).getChannelName());
        return convertView;
    }

    public static class ViewHolder {
        @ViewInject(R.id.food_channel_image)
        private ImageView imageView;
        @ViewInject(R.id.food_channel_name)
        private TextView textView;

        public ViewHolder(View convertView) {
            ViewUtils.inject(this, convertView);
        }
    }
}
